home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / Blasto-P / DirectScreen.p < prev   
Text File  |  1995-02-16  |  5KB  |  135 lines

  1. (* 11-11-92 • BRS changed things from short to long, to fix bug with THINK C compiler. *)
  2.  
  3.  
  4. {Decomment under UPI:}
  5. {$SETC GENERATINGPOWERPC=false}
  6.  
  7. unit DirectScreen;
  8.  
  9. interface
  10.  
  11. {$IFC UNDEFINED THINK_PASCAL}
  12.     uses
  13.         OSUtils, Windows, QDOffscreen, Retrace, Memory, Resources, Events,{}
  14.         Menus, ToolUtils;
  15. {$ENDC}
  16.  
  17.     type
  18.         LongPtr = ^Longint;
  19.     procedure DirectPlotColorIcon (colorIconPtr: LongPtr; screenPixMap: PixMapHandle; row: Integer; col: Integer);
  20.  
  21. implementation
  22.  
  23.     procedure DirectPlotColorIcon (colorIconPtr: LongPtr; screenPixMap: PixMapHandle; row: Integer; col: Integer);
  24. {     Draws a color icon image directly to the pixMap passed.}
  25. {    colorIconPtr = pointer to the image data for a color icon}
  26. {    screenPixMap = handle to the pixMap for the screen we're writing on}
  27. {    row, col      = location of the top left corner of the icon in the }
  28. {                    pixMap's coordinate system; }
  29. {                    since we know the icon is 32 by 32, }
  30. {                    the other coordinates are unnecessary. }
  31.         var
  32.             screenMemPtr: LongPtr;        { Pointer to video memory}
  33.             numRowsToCopy: LongInt;        { Rows we are going to copy}
  34.             stripRowBytes: LongInt;        { To clear high bit of rowbytes}
  35.             rowLongsOffset: LongInt;        { rowBytes converted to long}
  36.             mmuMode: SignedByte;                { 32-bit mode required}
  37.             cursRect: Rect;            { rectangle for shield cursor call}
  38.             cursOffset: Point;            { 0,0 to indicate rect is in global coordinates}
  39.     begin
  40.     (* High bit of pixMap rowBytes must be cleared. *)
  41.         stripRowBytes := BitAnd($7FFF, screenPixMap^^.rowBytes);
  42.  
  43.     (* We must strip the high byte of the address of the color icon, which, if we're in}
  44.     {24-bit mode, may be garbage when we go to 32-bit mode to access video memory. *)
  45. {$IFC GENERATINGPOWERPC }
  46.         colorIconPtr := LongPtr(colorIconPtr);
  47. {$ELSEC}
  48.         colorIconPtr := LongPtr(StripAddress(Ptr(colorIconPtr)));
  49. {$ENDC}
  50.  
  51.     (* Calculate the address of the first byte of the destination. *)
  52.         screenMemPtr := LongPtr(Longint(screenPixMap^^.baseAddr) + (stripRowBytes * row) + col); {GetPixBaseAddr???}
  53.  
  54.     (* call shield cursor to maintain compatibility with all displays *)
  55.     (* This rectangle should be a parameter, but this was added to late *)
  56.         cursOffset.h := 0;
  57.         cursOffset.v := 0;
  58.         cursRect.top := row;
  59.         cursRect.left := col;
  60.         cursRect.bottom := row + 32;
  61.         cursRect.right := col + 32;
  62.         ShieldCursor(cursRect, cursOffset);
  63.  
  64.     (* Change to 32-bit addressing mode to access video memory. The previous addressing mode }
  65.     { is returned in mmuMode for restoring later. *)
  66.         mmuMode := true32b;
  67. {$IFC NOT GENERATINGPOWERPC }
  68.         SwapMMUMode(mmuMode);
  69. {$ENDC}
  70.         numRowsToCopy := 32;                        (* Color icons have 32 rows. *)
  71.  
  72. (* Calculate the long word offset from the end of one row of the color icon on the screen's }
  73. {pixMap to the first byte of the icon in the next row. *)
  74.         rowLongsOffset := stripRowBytes - 32;
  75. {BSR(stripRowBytes, 2) - 8;}
  76.  
  77.     (* Draw the color icon directly to the screen. *)
  78.         repeat
  79. {^screenMemPtr++ := ^colorIconPtr++;}
  80. {^screenMemPtr++ := ^colorIconPtr++;}
  81. {^screenMemPtr++ := ^colorIconPtr++;}
  82. {^screenMemPtr++ := ^colorIconPtr++;}
  83. {^screenMemPtr++ := ^colorIconPtr++;}
  84. {^screenMemPtr++ := ^colorIconPtr++;}
  85. {^screenMemPtr++ := ^colorIconPtr++;}
  86. {^screenMemPtr++ := ^colorIconPtr++;}
  87.  
  88. {The Pascal version is quite a bit longer. It is, however, exactly as fast, according}
  89. {to my measurements. All that has happened is that we have to do some typecasts}
  90. {since Pascal doesn't enjoy pointer arithmetics, and we must add each separately.}
  91. {Big deal.}
  92.  
  93. {How bad would BlockMove be? If called by trap address? And how bad would it be with QuickDraw?}
  94. {And how much better with a row-list?}
  95.             {LongPtr(screenMemPtr)^ := LongPtr(colorIconPtr)^;}
  96.             {screenMemPtr := screenMemPtr + 4;}
  97.             {colorIconPtr := colorIconPtr + 4;}
  98.  
  99.             screenMemPtr^ := colorIconPtr^;
  100.             screenMemPtr := LongPtr(Longint(screenMemPtr) + 4);
  101.             colorIconPtr := LongPtr(Longint(colorIconPtr) + 4);
  102.             screenMemPtr^ := colorIconPtr^;
  103.             screenMemPtr := LongPtr(Longint(screenMemPtr) + 4);
  104.             colorIconPtr := LongPtr(Longint(colorIconPtr) + 4);
  105.             screenMemPtr^ := colorIconPtr^;
  106.             screenMemPtr := LongPtr(Longint(screenMemPtr) + 4);
  107.             colorIconPtr := LongPtr(Longint(colorIconPtr) + 4);
  108.             screenMemPtr^ := colorIconPtr^;
  109.             screenMemPtr := LongPtr(Longint(screenMemPtr) + 4);
  110.             colorIconPtr := LongPtr(Longint(colorIconPtr) + 4);
  111.             screenMemPtr^ := colorIconPtr^;
  112.             screenMemPtr := LongPtr(Longint(screenMemPtr) + 4);
  113.             colorIconPtr := LongPtr(Longint(colorIconPtr) + 4);
  114.             screenMemPtr^ := colorIconPtr^;
  115.             screenMemPtr := LongPtr(Longint(screenMemPtr) + 4);
  116.             colorIconPtr := LongPtr(Longint(colorIconPtr) + 4);
  117.             screenMemPtr^ := colorIconPtr^;
  118.             screenMemPtr := LongPtr(Longint(screenMemPtr) + 4);
  119.             colorIconPtr := LongPtr(Longint(colorIconPtr) + 4);
  120.             screenMemPtr^ := colorIconPtr^;
  121.             screenMemPtr := LongPtr(Longint(screenMemPtr) + 4);
  122.             colorIconPtr := LongPtr(Longint(colorIconPtr) + 4);
  123.  
  124.         (* Bump to start of next row. *)
  125.             screenMemPtr := LongPtr(Longint(screenMemPtr) + rowLongsOffset);
  126.  
  127.             numRowsToCopy := numRowsToCopy - 1;
  128.         until numRowsToCopy <= 0;
  129.  
  130. {$IFC NOT GENERATINGPOWERPC }
  131.         SwapMMUMode(mmuMode);        (* Restore addressing mode back to what it was. *)
  132. {$ENDC}
  133.         ShowCursor;
  134.     end;
  135. end.